﻿using System.Text;
using RAP.Framework.Libary.Utils;
using RAP.Framework.Libary.DomTemplateBuilder.Element;
using RAP.Framework.Libary.DomTemplateBuilder.Interface;

namespace RAP.Framework.Libary.DomTemplateBuilder.Handler
{
	/// <summary>
	/// 字典动作Handler
	/// </summary>
	public class DictionaryActionHandler : PropertyElementHandler
	{
		public const string DICTIONARY_OBJECT = "DictionaryObject";

		public new DictionaryAction Element
		{
			get
			{
				return base.Element as DictionaryAction;
			}
			set
			{
				base.Element = value;
			}
		}

		public override void DoRender ( StringBuilder writer, object rootParamObject, object parentParamObject, ITemplateRenderContext context )
		{
			object paramObject = null;
			if ( !this.Property.IsNullOrEmpty ( ) )
			{
				paramObject = this.GetPropertyValue ( rootParamObject, parentParamObject, context );
			}
			else
			{
				paramObject = this.GetParamObject ( rootParamObject, parentParamObject, context );
			}
			var dicTmp = context[ DICTIONARY_OBJECT ];
			context[ DICTIONARY_OBJECT ] = paramObject;
			base.DoRender ( writer, rootParamObject, parentParamObject, context );
			context[ DICTIONARY_OBJECT ] = dicTmp;
		}

	}
}
